/**
 * This file is part of the Kompics P2P Framework.
 *
 * Copyright (C) 2009 Swedish Institute of Computer Science (SICS)
 * Copyright (C) 2009 Royal Institute of Technology (KTH)
 *
 * Kompics is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package se.sics.drsm.ports.drsm.events;

import se.sics.drsm.model.DRSMAddress;
import se.sics.drsm.model.LookupInfo;
import se.sics.drsm.overlay_address.key.NumericRingKey;
import se.sics.kompics.Response;

import java.util.List;

/**
 * The <code>DRSMLookupResponse</code> class.
 *
 * @author Cosmin Arad <cosmin@sics.se>
 * @author Shadid Chowdhury <msrch@kth.se>
 */
public final class DRSMLookupResponse extends Response {

    /**
     * The <code>DRSMLookupStatus</code> class.
     *
     * @author Cosmin Arad <cosmin@sics.se>
     * @author Shadid Chowdhury <msrch@kth.se>
     */
    public static enum DRSMLookupStatus {
        SUCCESS, FAILURE
    }

    //TODO: Add a new field called configuration. with indication of the leader
    private final NumericRingKey key;

    private final List<DRSMAddress> responsible;

    private final DRSMAddress suspected;

    private final Object attachment;

    private final LookupInfo lookupInfo;

    private final DRSMLookupStatus status;

    private final Boolean isJoinRequest;

    public DRSMLookupResponse(DRSMLookupRequest request, NumericRingKey key,
                              List<DRSMAddress> responsible, Object attachment, LookupInfo lookupInfo, boolean isJoinRequest) {
        super(request);
        this.key = key;
        this.responsible = responsible;
        this.suspected = null;
        this.attachment = attachment;
        this.lookupInfo = lookupInfo;
        this.status = DRSMLookupStatus.SUCCESS;
        this.isJoinRequest = isJoinRequest;
    }

    public DRSMLookupResponse(DRSMLookupRequest request, NumericRingKey key,
                              Object attachment, DRSMAddress suspectedPeer, boolean isJoinRequest) { //FIXME; why suspected?
        super(request);
        this.key = key;
        this.attachment = attachment;
        this.responsible = null;
        this.suspected = suspectedPeer;
        this.lookupInfo = null;
        this.status = DRSMLookupStatus.FAILURE;
        this.isJoinRequest = isJoinRequest;
    }

    public NumericRingKey getKey() {
        return key;
    }

    public List<DRSMAddress> getResponsible() {
        return responsible;
    }

    public Object getAttachment() {
        return attachment;
    }

    public LookupInfo getLookupInfo() {
        return lookupInfo;
    }

    public DRSMLookupStatus getStatus() {
        return status;
    }

    public DRSMAddress getSuspected() {
        return suspected;
    }

    public Boolean isJoinRequest() {
        return isJoinRequest;
    }

}

